#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;



int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> compere;
    compere.reserve(n);
    for(int i = 0, x, y; i < n; i++) 
    {
        cin >> x >> y;
        compere.emplace_back(x, y);
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pri_compere;
    sort(compere.begin(), compere.end());
    pri_compere.emplace(compere[0].first, compere[0].second);
    for(size_t i = 1; i < compere.size(); i++)
    {
        if(compere[i].first >= pri_compere.top().second)
        {
            pri_compere.pop();
            pri_compere.emplace(compere[i].first, compere[i].second);
            continue;
        }
        pri_compere.emplace(compere[i].first, compere[i].second);
    }
    cout << pri_compere.size() << endl;
    return 0;
}